// 云函数入口文件
const cloud = require('wx-server-sdk')


cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database()
const _ = db.command
const $ = db.command.aggregate

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  var pw = event.password
  var ad = event.admin
  console.log(event)
  console.log("debug")
  return new Promise((reslove,reject)=>{
    db.collection('admin').aggregate()
    .match({
      admin:_.eq(ad),
      password:_.eq(pw)
    }).end().then(res=>{
      if(res.list.length){
        reslove({code:200,message:"登录成功",data:res.list[0]})
      }
      else {
        reslove({code:404,message:"登录失败"})
      }
    })
  })
  

}